package com.chushouya.controller.product.admin;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateDetailDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateListDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateQuery;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateSaveDTO;
import com.chushouya.product.dto.admin.tempevaluate.TempEvaluateUpdateDTO;
import com.chushouya.product.service.admin.TempEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "模板估价管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/tempEvaluate")
public class TempEvaluateController {

    @Resource
    private TempEvaluateService tempEvaluateService;

    @ApiOperation("获取模板估价分页列表")
    @GetMapping("/page")
    public Response<PageResult<TempEvaluateListDTO>> page(TempEvaluateQuery query) {
        return Response.success(tempEvaluateService.selectTempEvaluatePageResult(query));
    }

    @ApiOperation("获取模板估价列表")
    @GetMapping("/list")
    public Response<List<TempEvaluateListDTO>> list(TempEvaluateQuery query) {
        return Response.success(tempEvaluateService.selectTempEvaluateList(query));
    }

    @ApiOperation("根据ID获取模板估价详细信息")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempId", value = "模板ID", required = true),
    })
    public Response<TempEvaluateDetailDTO> getDetail(Long tempId) {
        return Response.success(tempEvaluateService.getTempEvaluateDetail(tempId));
    }

    @ApiOperation("新增模板估价")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @RepeatSubmit
    public Response<Long> add(@Validated @RequestBody TempEvaluateSaveDTO tempEvaluate) {
        return Response.success(tempEvaluateService.addTempEvaluate(tempEvaluate));
    }

    @ApiOperation("修改模板估价")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<Void> edit(@Validated @RequestBody TempEvaluateUpdateDTO tempEvaluate) {
        tempEvaluateService.editTempEvaluate(tempEvaluate);
        return Response.success();
    }

    @ApiOperation("删除模板估价")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tempId", value = "模板ID", required = true)
    })
    public Response<Void> remove(Long tempId) {
        tempEvaluateService.removeTempEvaluate(tempId);
        return Response.success();
    }

    @ApiOperation("根据分类ID获取模板估价列表")
    @GetMapping("/listByCategoryId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "分类ID", required = true)
    })
    public Response<List<TempEvaluateListDTO>> listByCategoryId(Long categoryId) {
        return Response.success(tempEvaluateService.selectTempEvaluateListByCategoryId(categoryId));
    }
}
